<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <link href="http://g.alicdn.com/bui/bui/1.1.21/css/bs3/dpl.css" rel="stylesheet">
    <link href="http://g.alicdn.com/bui/bui/1.1.21/css/bs3/bui.css" rel="stylesheet">
    <link rel="stylesheet" href="<%=basePath%>static/bui-admin/index.css">
    <script src="http://g.tbcdn.cn/fi/bui/jquery-1.8.1.min.js"></script>
    <script src="http://g.alicdn.com/bui/bui/1.1.21/bui.js"></script>
</head>
<body>
<div class="row span16 offset8">
    <div class="panel xm-login-panel">
        <div class="panel-header">
            <h3 class="panel-title"><b>一元鸡</b>-后台</h3>
        </div>
        <div class="panel-body">
            <form class="form-horizontal well" id="loginForm">
                <div class="row">
                    <div class="control-group span8">
                        <label class="control-label">账号：</label>

                        <div class="controls">
                            <input type="text" placeholder="账号" name="loginName" class="control-text"
                                   autofocus/>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="control-group span8">
                        <label class="control-label">密码：</label>

                        <div class="controls">
                            <input type="password" name="pwd" placeholder="密码" class="control-text" label="密码"/>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="form-actions offset3">
                        <button type="submit" class="button button-large button-primary">登陆</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<script>
    var form = new BUI.Form.HForm({
        srcNode : '#loginForm'
    }).render();

    form.on('beforesubmit',function(ev) {
        //序列化成对象
        var obj = form.serializeToObject();
        $.ajax({
            type:"POST",
            dataType:"json",
            url:"<%=basePath%>rest/web/login",
            data:obj,
            success:function(data) {
                if(data.code=="-1"){
                    alert(data.msg)
                }else{
                    window.location.href="<%=basePath%>rest/web/toUser";
                }
            }
        });
        return false;
    });
</script>
</body>
</html>
